$(function() {
	var delTermArr = [];
	// var checkedWeight = 0;
	//显示菜单信息
	var head = $("#breadcrumbs");
	// var headText = $("#breadcrumbs").text().trim();
	head.html('<ul class="breadcrumb">' +
		'<li><i class="icon-home"></i> <a href="/">首页</a><span class="divider"><i class="icon-angle-right"></i></span></li>' +
		'<li><a href="#">绩效管理</a> <span class="divider"><i class="icon-angle-right"></i></span></li>' +
		'<li class="active">绩效目标填写</li></ul>');

	//获取服务器当前时间
	var http = new XMLHttpRequest;
	http.open("HEAD", ".", false);
	http.send(null);
	var today = new Date(http.getResponseHeader("Date"));
	var year_today = today.getFullYear();
	var month_today = (today.getMonth() + 1) < 10 ? "0" + (today.getMonth() + 1) : (today.getMonth() + 1);
	var day = today.getDate() < 10 ? "0" + today.getDate() : today.getDate();
	var nextMonth = "";
	if (month_today == 12) {
		nextMonth = "01";
	} else {
		nextMonth = (today.getMonth() + 2) < 10 ? "0" + (today.getMonth() + 2) : (today.getMonth() + 2);
	}

	// 每个月的23-26号才能够填写绩效
	if (day >= 23 && day <= 26) {
		$("#tip").html("");
		$("#wholePage").css('display', 'block');

	} else {
		var access = $("#getAccess").val();
		if (access == "填写") {
			$("#tip").html("");
			$("#wholePage").css('display', 'block');
		} else {
			$('#tip').html("<div class='alert alert-warning' style='margin-top:-20px;'>每月的23-26号才可以填写绩效目标</div>");
		}
		// $('#tip').html("<div class='alert alert-warning' style='margin-top:-20px;'>每月的23-26号才可以填写绩效目标</div>");
	}


	//初始化时间选择器
	// $('#perfDate').datepicker({
	// 	autoclose: true,
	// 	todayBtn: true,
	// 	startView: 1,
	// 	minViewMode: 1
	// });

	document.onclick = function(evt) {
		var event = evt || window.event;
		var obj = event.srcElement || event.target;

		if (obj.id == "deleteIcon") {
			obj = obj.parentNode.parentNode;
			if (navigator.userAgent.indexOf("MSIE") > 0) {
				obj.removeNode(true);
			} else if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
				obj.parentNode.removeChild(obj);
			} else {
				obj.remove();
			}
		}
	}
	//工作项表格增行
	$("#btnadd").click(function() {

		var template = "<tr><td class=span3><textarea style='resize:none;text-align:left;height:100%' type='text' id='term' name='term'  class='span12'></textarea></td>" +
			"<td class=span3><textarea style='resize:none;text-align:left;height:100%' type='text' id='content' name='content'  class='span12'></textarea></td>" +
			"<td class=span2 hidden-480 style='vertical-align:middle;'><input style='text-align: center;height: 100%' type='text' id='weight' name='weight'  class='span12'/></td>" +
			"<td class=span3 hidden-phone style='vertical-align:middle;'><input type='hidden' id='assessmentPersonId' name='assessmentPersonId' /><input type='hidden' name='hideName3'/><input style='text-align: center;height: 100%' type='text' name='assessmentPerson' id='assessmentPerson' class='span12'/><input type='hidden' id='assessmentPersonEmail' name='assessmentPersonEmail'/></td>" +
		// "<td class=span2 hidden-480></td>"+
		"<td class=span2 style='text-align:center;vertical-align:middle;'><i style='cursor:pointer;' id=deleteIcon name=deleteIcon class='icon-trash  bigger-150';></i></td></tr>";
		var $html = $(Mustache.to_html(template, null));
		$("#tbd").append($html);
		$html.find("#assessmentPerson").blur({
			html: $html
		}, function(e) {
			var $html = $(e.data.html);
			var assPersonId = $html.find("#assessmentPersonId").val();
			var assPersonNam3 = $html.find("#assessmentPerson").val().replace(/(^\s*)|(\s*$)/g, "");
			var hideName3 = $html.find("#hideName3").val();

			if (assPersonNam3 == "") {
				$html.find("#assessmentPersonId").val("");
				$html.find("#hideName3").val("");

			} else {
				$.ajax({
					url: '/api/employee/selAssEmpByName?',
					type: 'get',
					data: {
						'empName': assPersonNam3,
						'_t': new Date().getTime()
					},
					success: function(result) {
						// console.info("33333--result", result);
						// alert("33333----" + result.length);
						if (result != null && result.length != 0 && result != "none") {
							if (assPersonId == null || assPersonId == "" || assPersonId == 0) {
								$html.find("#assessmentPersonId").val(result[0].id);
								$html.find("#assessmentPersonEmail").val(result[0].email);
							} else if (result[0].name != hideName3) {
								$html.find("#assessmentPersonId").val(result[0].id);
								$html.find("#assessmentPersonEmail").val(result[0].email);
							}
						} else {
							$html.find("#assessmentPerson").val("");
							$html.find("#assessmentPersonId").val("");
							bootbox.alert("该员工没有审核权限或不存在！");
						}
					}
				});
			}
		});
		// $("#tbd").append(template);
		document.onclick = function(evt) {
			var event = evt || window.event;
			var obj = event.srcElement || event.target;

			if (obj.id == "deleteIcon") {
				obj = obj.parentNode.parentNode;
				if (navigator.userAgent.indexOf("MSIE") > 0) {
					obj.removeNode(true);
				} else if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
					obj.parentNode.removeChild(obj);
				} else {
					obj.remove();
				}
			}
		}

		$("input[name='assessmentPerson']").autocomplete({
			source: availableTags,
			select: function(event, ui) {
				// console.info(event.target.parentNode.getElementsByName(assessmentPersonId));
				event.target.parentNode.firstChild.value = ui.item.empId;
				event.target.parentNode.lastChild.value = ui.item.email;
			}
		});

	});


	//保存绩效项
	$("#saveBtn").click(function() {
		var sendData = buildModel();
		// console.info("save--delTermArr:",delTermArr);
		// return;
		sendData.deleteItems = delTermArr;
		if (!sendData.termCheck) {
			bootbox.alert("请填写工作事项！");
			return;
		}
		if (!sendData.contentCheck) {
			bootbox.alert("请填写预期成果描述！");
			return;
		}
		if (!sendData.weightCheck) {
			bootbox.alert("权重要大于零！");
			return;
		}
		if (sendData.totalWeight != 100) {
			bootbox.alert("工作任务及目标权重总和不等于100%！");
			return;
		}
		if (!sendData.assPersonCheck) {
			bootbox.alert("请填写考核人！");
			return;
		}
		if (!sendData.projectlengthCheck) {
			bootbox.alert("项目不得超过25字！");
			return;
		}
		if (!sendData.lengthCheck) {
			bootbox.alert("填写内容不得超过120字！");
			return;
		}

		if (sendData.preDeptId == "") {
			sendData.preDeptId = 0;
		}
		var perfId = $("#perfId").val();
		var type;
		if (perfId == null || perfId == "") {
			type = "post"
		} else {
			type = "put"
			sendData.perfId = perfId;
		}

		if (sendData.employeeId == null || sendData.employeeId == "") {
			bootbox.alert("请填写被考核人！");
			return;
		}
		if (sendData.departmentId == null || sendData.departmentId == "") {
			bootbox.alert("请选择部门！");
			return;
		}
		// if(sendData.assessmentPersonId == null || sendData.assessmentPersonId == "") {
		// 	bootbox.alert("请选择考核人！");
		// 	return;
		// }
		// console.info(sendData);
		// return;

		//校验同一月份的绩效信息是否已存在
		$.ajax({
			url: '/api/performance/checkExist?',
			type: 'get',
			data: {
				'empId': sendData.employeeId,
				'perfDate': sendData.perfDate,
				'_t': new Date().getTime()
			},
			success: function(result) {
				if (result != null && result.length != 0) {
					if (result[0].id == sendData.perfId && type == "put") {
						sendData.operation = "修改";
						saveEmpPerf(type, sendData);
					} else {
						var dateArr = sendData.perfDate.split('-');
						bootbox.alert(dateArr[0] + "年" + dateArr[1] + "月的任务及目标已填写！");
					}
				} else {
					saveEmpPerf(type, sendData);
				}
				// if(result) {
				// 	saveEmpPerf(type, sendData);
				// }else{
				// 	var dateArr = sendData.perfDate.split('-');
				// 	// console.log(dateArr);
				// 	bootbox.alert(dateArr[0] + "年" + dateArr[1] + "月的任务及目标已填写！");
				// }
			}
		});

		// $.ajax({
		// 	url: '/api/performance/saveOrUpdatePer',
		// 	type: type,
		// 	data: sendData,
		// 	success: function(result) {
		// 		bootbox.alert(result, function() {
		// 			window.location.href = "/desktop";
		// 		});

		// 	},
		// 	error: function(result) {
		// 		bootbox.alert("绩效信息保存失败！");
		// 	}
		// });
	});

	var saveEmpPerf = function(type, sendData) {
		$.ajax({
			url: '/api/performance',
			type: type,
			data: sendData,
			success: function(result) {
				if (result == 'noPrivilege') {
					bootbox.alert('您没有权限,操作失败！');
					return;
				} else if (result == 'without auth or user info') {
					window.location.href = "/";
				}
				bootbox.alert(result, function() {
					window.location.href = "/desktop";
				});

			},
			error: function(result) {
				bootbox.alert("绩效信息保存失败！");
			}
		});
	};

	//取消选择部门
	$("#cancle").click(function() {
		// $("#department").val("");
		// $("#deptId").val("");
		$("#showOrgs").modal('hide');
	});

	//选择部门
	$("#chooseDept").click(function() {
		$("#chooseOrg").html("");
		$("#showOrgs").modal("show");
		$("#chooseOrg").ligerTree({
			url: '/api/organizations/getOrgTree?_t=' + new Date().getTime(),
			method: 'get',
			checkbox: false,
			nodeWidth: 120,
			idFieldName: "id",
			parentIDFieldName: 'pid',
			slide: false,
			onSelect: function(node) {
				actionNodeID = node.data.id;
				getOrgParents(actionNodeID, 1);


			}
		});
	});

	var getOrgParents = function(orgId, type) {
		//type=0--员工所在部门；type=1--工程部门
		$.ajax({
			url: '/api/organizations/getParents/' + orgId,
			type: 'get',
			data: {
				'_t': new Date().getTime()
			},
			success: function(result) {
				// console.info(result);
				var parentString = "";
				for (var i = result.length - 1; i >= 0; i--) {
					if (i != 0) {
						if (result[i].orgName == "分公司") {
							continue;
						} else {
							parentString += result[i].orgName + "/";
						}

					} else {
						parentString += result[i].orgName;
					}
				}
				if (type == 1) {
					$("#projectDept").val(parentString);
					$("#preDeptId").val(result[0].id);
				} else {
					$("#department").val(parentString);
					$("#deptId").val(result[0].id);
				}

				$("#showOrgs").modal('hide');


			}
		});
	};

	//构建数据模型
	var buildModel = function() {
		var termArr = $("textarea[name='term']");
		var contentArr = $("textarea[name='content']");
		var weightArr = $("input[name='weight']");
		var termIdArr = $("input[name='termId']");
		var assPersonIdArr = $("input[name='assessmentPersonId']");
		var assPersonEmailArr=$("input[name='assessmentPersonEmail']");
		var stateArr = $("input[name='perfState']");
		// alert(termArr.length);
		//新增的绩效项
		var basicItems = [];
		//更新的绩效项
		var updateItems = [];
		//权重总和
		var weightCheck = true;
		var totalWeight = 0;
		// console.info("checkedWeight = " + checkedWeight);
		// if (checkedWeight != undefined && checkedWeight != null) {
		// 	totalWeight += checkedWeight;
		// }
		// console.info("totalWeight = " + totalWeight);

		var termCheck = true;
		var contentCheck = true;
		var assPersonCheck = true;
		var lengthCheck = true;
		var projectlengthCheck = true;


		//工作事项数据
		termArr.each(function(item) {
			// console.info("$(assPersonIdArr[item]).val()=",$(assPersonIdArr[item]).val());
			var term = $(termArr[item]).val().replace(/(^\s*)|(\s*$)/g, "");
			var content = $(contentArr[item]).val().replace(/(^\s*)|(\s*$)/g, "");

			if (term.length > 120 || content.length > 120) {
				lengthCheck = false;
			}
			if (term == "") {
				termCheck = false;
			}
			if (content == "") {
				contentCheck = false;
			}
			if ($(assPersonIdArr[item]).val() == "") {
				assPersonCheck = false;
			}
			// console.info(item + "---:" +  $(stateArr[item]).val());
			var state = 0;
			if ($(stateArr[item]).val() != undefined && $(stateArr[item]).val() != "") {
				state = parseInt($(stateArr[item]).val());
			}
			var itemData = {
				term: term,
				content: content,
				weight: parseFloat($(weightArr[item]).val()),
				assPersonId: $(assPersonIdArr[item]).val(),
				assPersonEmail:$(assPersonEmailArr[item]).val(),
				state: state,
				type: 0
			};
			if (itemData.weight <= 0) {
				weightCheck = false;
			}

			totalWeight += parseFloat($(weightArr[item]).val());
			var termId = $(termIdArr[item]).val();
			// console.info(item + '----' + termId);
			//已审核绩效项不需要更新
			if (state == 0) {
				if (termId != null && termId != "") {
					itemData.termId = termId;
					updateItems.push(itemData);
				} else {
					basicItems.push(itemData);
				}

			}

			// basicItems.push(itemData);
		});
		// console.info("-----------basicItems----" );
		// console.info(basicItems);

		// var assessmentPersonId = $("#assessmentid").val();//考核人id
		// var assessmentPer = $("#assessmentPerson").val();//考核人姓名
		var employeeId = $("#employeeid").val(); //被考核人id
		var employee = $("#employee").val(); //被考核人姓名
		var perfDate = $("#perfDate").val(); //审核时间
		var departmentId = $("#deptId").val(); //行政部门
		var preDeptId = $("#preDeptId").val(); //工程部门
		var project = $("#project").val().replace(/(^\s*)|(\s*$)/g, ""); //项目名称
		if (project.length > 25) {
			projectlengthCheck = false;
		}
		var performanceData = {
			basicItems: basicItems,
			updateItems: updateItems,
			// assessmentPersonId: assessmentPersonId,
			employeeId: employeeId,
			employee: employee,
			perfDate: perfDate,
			departmentId: departmentId,
			totalWeight: totalWeight,
			state: 0,
			preDeptId: preDeptId,
			project: project,
			termCheck: termCheck,
			contentCheck: contentCheck,
			assPersonCheck: assPersonCheck,
			weightCheck: weightCheck,
			lengthCheck: lengthCheck,
			projectlengthCheck: projectlengthCheck
		};
		return performanceData;
	};


	var availableTags = [];
	var getEmps = function() {
		var empId = $("#empId").val();
		$.ajax({
			url: '/api/employee/selByRole?',
			type: 'get',
			data: {
				'_t': new Date().getTime()
			},
			success: function(data) {
				// console.info(data);
				if (data != "none") {
					for (var i = 0; i < data.length; i++) {
						// console.info(data[i].id);
						if (data[i].id != empId) {
							var showStr = data[i].name + "-" + data[i].orgAddress + "-" + data[i].orgName;
							var item = {
								label: showStr,
								value: data[i].name,
								empId: data[i].id,
								email: data[i].email
							}
							availableTags.push(item);
						}

					}
				}
			}
		});
	};

	getEmps();

	$("#assessmentPerson").autocomplete({
		source: availableTags,
		select: function(event, ui) {
			$("#assessmentPersonId").val(ui.item.empId);
			$("#assessmentPersonEmail").val(ui.item.email);
		}
	});
	$("#assessmentPerson").blur(function() {
		var assPersonId = $("#assessmentPersonId").val();
		var assPersonNam = $("#assessmentPerson").val().replace(/(^\s*)|(\s*$)/g, "");
		var hideName1 = $("#hideName1").val();
		if (assPersonNam == "") {
			$("#assessmentPersonId").val("");
			$("#hideName1").val("");
		} else {
			$.ajax({
				url: '/api/employee/selAssEmpByName?',
				type: 'get',
				data: {
					'empName': assPersonNam,
					'_t': new Date().getTime()
				},
				success: function(result) {
					// console.info("11111--result", result);
					// alert("11111----" + result.length);
					if (result != null && result.length != 0 && result != "none") {
						if (assPersonId == null || assPersonId == "" || assPersonId == 0) {
							$("#assessmentPersonId").val(result[0].id);
							$("#assessmentPersonEmail").val(result[0].email);
						} else if (result[0].name != hideName1) {
							$("#assessmentPersonId").val(result[0].id);
							$("#assessmentPersonEmail").val(result[0].email);
						}
					} else {
						$("#assessmentPerson").val("");
						$("#assessmentPersonId").val("");
						bootbox.alert("该员工没有审核权限或不存在！");
					}
				}
			});
		}

	});

	$("#employee").autocomplete({
		source: availableTags,
		select: function(event, ui) {
			$("#employeeid").val(ui.item.empId);
		}
	});
	var init = function() {
		var year = $("#getYear").val();
		var month = $("#getMonth").val();
		// console.info("year = " + year + "------month = " + month);
		var timeStr = year + "-" + month;
		//去除前后空格
		timeStr = timeStr.replace(/(^\s*)|(\s*$)/g, "");
		//年月不为空表示从桌面月历跳转查看/修改未审核绩效目标或填写绩效目标
		if (year != "" && month != "") {
			initData(timeStr);

		} else {
			//自动填充员工基本信息

			var time;
			if (month_today == 12) {
				time = (year_today + 1) + "-01";
			} else {
				time = year_today + "-" + nextMonth;
			}
			initData(time);

		}

	};
	var initData = function(timeStr) {
		// alert(timeStr);
		$.ajax({
			url: '/api/performance/selMonthPerf/' + timeStr + '?',
			type: 'get',
			data: {
				'_t': new Date().getTime()
			},
			success: function(data) {
				// console.info(data);
				if (data != null && data.perData.length != 0 && data.perData[0].state == 0) {
					var perfData = data.perData[0];
					var termsData = data.termsData;
					$("#perfDate").val(perfData.perfDate);
					$("#perfId").val(perfData.id);
					$("#employeeid").val(perfData.employeeId);
					$("#employee").val(perfData.empName);
					$("#assessmentid").val(perfData.assessmentPersonId);
					$("#assessmentPerson").val(perfData.assname);
					$("#deptId").val(perfData.departmentId);


					getOrgParents(perfData.departmentId, 0);
					// console.log(perfData.preDeptId == null);
					if (perfData.preDeptId != null) {
						$("#preDeptId").val(perfData.preDeptId);
						getOrgParents(perfData.preDeptId, 1)
					}
					if (perfData.project != null) {
						$("#project").val(perfData.project);
					}
					// getOrgParents(perfData.preDeptId, 1);
					// console.info("termsData");
					// console.info(termsData);
					showTerms(termsData);
					// $("#department").val(perfData.departmentId);

				} else {
					//自动填充员工基本信息
					timeArr = timeStr.split("-");
					// console.info("timeArr:", timeArr);
					var year = timeArr[0];
					var month = timeArr[1]
					if (month_today == 12) {
						if (!(month == month_today && year == year_today) && !(month == "01" && year == (year_today + 1))) {
							timeStr = (year_today + 1) + "-01";
						}
					} else if (!(month == month_today && year == year_today) && !(month == nextMonth && year == year_today)) {
						timeStr = year_today + "-" + nextMonth;
					}
					$.ajax({
						url: '/api/employee/getEmpByUser?',
						type: 'get',
						data: {
							'_t': new Date().getTime()
						},
						success: function(data) {
							// console.info("data:",data);
							$("#employeeid").val(data.id);
							$("#employee").val(data.name);
							$("#deptId").val(data.departmentId);
							$("#perfDate").val(timeStr);
							getOrgParents(data.departmentId, 0);
						}
					});
				}
			}
		});
	}

	init();

	var showTerms = function(termsData) {
		// console.info("termsData",termsData);
		if (termsData != null && termsData.length != 0) {
			$("#tbd").html('');

			$.each(termsData, function(i, item) {
				if (item.type == 0) {
					item.weight = item.weight + "%";
					var templateData = {
						itemId: item.id,
						term: item.term,
						content: item.content,
						weight: item.weight,
						name: item.name,
						assPersonId: item.assPersonId,
						state: item.state,
						email:item.email

					};
					var template = "";
					if (item.state == 0) {

						template = "<tr><td class=span3><input type='hidden' id='perfState' name='perfState' value={{state}} /><input type='hidden' id='termId' name='termId' value={{itemId}} /><textarea style='resize:none;text-align:left;height:100%' type='text' id='term' name='term' class='span12'>{{term}}</textarea></td>" +
							"<td class=span3><textarea style='resize:none;text-align:left;height:100%' type='text' id='content' name='content' class='span12'>{{content}}</textarea></td>" +
							"<td class=span2 hidden-480 style='vertical-align:middle;'><input style='text-align: center;height: 100%' type='text' id='weight' name='weight' value={{weight}} class='span12'/></td>" +
							"<td class=span3 hidden-phone style='vertical-align:middle;'><input type='hidden' id='assessmentPersonId' name='assessmentPersonId' value={{assPersonId}} /><input type='hidden' name='hideName2' value={{name}} /><input style='text-align: center;height: 100%' type='text' id='assessmentPerson' name='assessmentPerson' value={{name}}  class='span12'/><input type='hidden' id='assessmentPersonEmail' name='assessmentPersonEmail' value={{email}} /></td>" +
							"<td class=span2 style='text-align:center;vertical-align:middle;'><i style='cursor:pointer;' id=delIcon name=delIcon class='icon-trash  bigger-150';></i></td></tr>"


					} else {
						// checkedWeight += parseInt(item.weight);
						template = "<tr><td class=span3><input type='hidden' id='perfState' name='perfState' value={{state}} /><input type='hidden' id='termId' name='termId' value={{itemId}} /><textarea readonly='true' style='resize:none;text-align:left;height:100%' type='text' id='term' name='term' class='span12'>{{term}}</textarea></td>" +
							"<td class=span3><textarea readonly='true' style='resize:none;text-align:left;height:100%' type='text' id='content' name='content' class='span12'>{{content}}</textarea></td>" +
							"<td class=span2 hidden-480 style='vertical-align:middle;'><input readonly='true' style='text-align: center;height: 100%' type='text' id='weight' name='weight' value={{weight}} class='span12'/></td>" +
							"<td class=span3 hidden-phone style='vertical-align:middle;'><input type='hidden' id='assessmentPersonId' name='assessmentPersonId' value={{assPersonId}} /><input type='hidden' name='hideName2' value={{name}} /><input readonly='true' style='text-align: center;height: 100%' type='text' id='assessmentPerson' name='assessmentPerson' value={{name}}  class='span12'/><input type='hidden' id='assessmentPersonEmail' name='assessmentPersonEmail' value={{email}} /></td>" +
							"<td class=span2 style='text-align:center;vertical-align:middle;'><i style='cursor:pointer;' class='icon-trash  bigger-150';></i></td></tr>"


					}
					var $html = $(Mustache.to_html(template, templateData));
					$("#tbd").append($html);
					$("input[name='assessmentPerson']").autocomplete({
						source: availableTags,
						select: function(event, ui) {
							// console.info(event.target.parentNode.getElementsByName(assessmentPersonId));
							event.target.parentNode.firstChild.value = ui.item.empId;
							event.target.parentNode.lastChild.value = ui.item.email;
						}
					});

					$html.find("#assessmentPerson").blur({
						html: $html
					}, function(e) {
						var $html = $(e.data.html);
						var assPersonId = $html.find("#assessmentPersonId").val();
						var assPersonNam2 = $html.find("#assessmentPerson").val().replace(/(^\s*)|(\s*$)/g, "");
						var hideName2 = $html.find("#hideName2").val();
						// console.info("-----", $html.find("#assessmentPersonId").val());
						// alert("assPersonNam2="+assPersonNam2);
						if (assPersonNam2 == "") {
							$html.find("#assessmentPersonId").val("");
							$html.find("#hideName2").val("");

						} else {
							$.ajax({
								url: '/api/employee/selAssEmpByName?',
								type: 'get',
								data: {
									'empName': assPersonNam2,
									'_t': new Date().getTime()
								},
								success: function(result) {
									// alert("2222222----" +result);
									// console.info("2222--result", result);
									if (result != null && result.length != 0 && result != "none") {
										if (assPersonId == null || assPersonId == "" || assPersonId == 0) {
											$html.find("#assessmentPersonId").val(result[0].id);
											$html.find("#assessmentPersonEmail").val(result[0].email);
										} else if (result[0].name != hideName2) {
											$html.find("#assessmentPersonId").val(result[0].id);
											$html.find("#assessmentPersonEmail").val(result[0].email);
										}
									} else {
										$html.find("#assessmentPerson").val("");
										$html.find("#assessmentPersonId").val("");
										bootbox.alert("该员工没有审核权限或不存在！");
									}
								}
							});
						}
					});


					$html.find('#delIcon').click({
						html: $html
					}, function(e) {
						var $html = $(e.data.html);
						var termId = $html.find('#termId').val();
						var delTerm = $html.find('#term').val();

						bootbox.confirm("确定删除工作事项【" + delTerm + "】吗？", function(result) {
							if (!result) {
								return;
							} else {

								delTermArr.push(termId);
								// console.info("delete term --delTermArr:", delTermArr);
								// $.ajax({
								// 	url: '/api/performance/delPerfTerm?termId=' + termId,
								// 	type: 'delete',
								// 	success: function(result) {
								// 		// console.info(result);
								// 		$html.remove();
								// 	},
								// 	error: function(result) {
								// 		console.info("删除工作事项失败！" + result);
								// 	}
								// });

								$html.remove();
							}
						});
					});


				}



			});
		} else {
			return;
		}
	};


});